#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h> 
#include <ctype.h>

#define MAX_ROW_LENGTH  4096
#define MAX_FILE_NAME   128
#define GENERATE_PATH   "./gen"

int strupr(char* dst,char* src)
{
	if(!src || !dst){
		return -EINVAL;
	}
	while ((*src) != '\0'){
		if((*src) >= 'a' && (*src) <= 'z'){
			(*dst) = (*src) - 0x20;
		}else{
			(*dst) = (*src);
		}
		src++;
		dst++;
	}
	(*dst) = '\0';
	return 0;
}

int generate_h(char* name)
{
	int len = 0;
	int size = MAX_ROW_LENGTH;
	char filename[MAX_FILE_NAME];
	char uname[MAX_FILE_NAME];
	char row[MAX_ROW_LENGTH];
	FILE* fp;

	sprintf(filename,"%s/%s.h",GENERATE_PATH,name);
	if(!access(filename,R_OK)){
		printf("%s have existed, will be replaced\n",filename);
		remove(filename);
	}
	fp = fopen(filename,"w+");
	if(!fp){
		printf("open h file error\n");
		return -EFAULT;
	}
	strupr(uname,name);
	len = 0;
	len += snprintf(row + len, size - len,"#ifndef __%s_H__ \n",uname);
	len += snprintf(row + len, size - len,"#define __%s_H__\n",uname);
	len += snprintf(row + len, size - len,"#include <stdint.h>\n");
	len += snprintf(row + len, size - len,"#include \"list.h\"\n");
	len += snprintf(row + len, size - len,"#include \"lock.h\"\n");
	len += snprintf(row + len, size - len,"#include \"wait.h\"\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"struct %s_frame\n",name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    struct list_head head;\n");
	len += snprintf(row + len, size - len,"    int size;\n");
	len += snprintf(row + len, size - len,"    uint8_t data[32];\n");
	len += snprintf(row + len, size - len,"};\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"struct %s;\n\n",name);
	fwrite(row,len,1,fp);

	len = 0;
	len += snprintf(row + len, size - len,"#define %s_CACHE_COUNT	4\n\n",uname);
	fwrite(row,len,1,fp);

	len = 0;
	len += snprintf(row + len, size - len,"enum %s_EVENT\n",uname);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    %s_EVENT_NONE = 0,\n",uname);
	len += snprintf(row + len, size - len,"    %s_EVENT_TEST,\n",uname);
	len += snprintf(row + len, size - len,"    %s_EVENT_MAX,\n",uname);
	len += snprintf(row + len, size - len,"};\n\n");
	fwrite(row,len,1,fp);

	len = 0;
	len += snprintf(row + len, size - len,"typedef int32_t (*%s_event_notify)(struct %s*, int32_t, void*, void*);\n\n",name,name);
	fwrite(row,len,1,fp);

	len = 0;
	len += snprintf(row + len, size - len,"struct %s_event_action\n",name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    %s_event_notify notify;\n",name);
	len += snprintf(row + len, size - len,"    void* object;\n");
	len += snprintf(row + len, size - len,"    struct %s_event_action* next;\n",name);
	len += snprintf(row + len, size - len,"};\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"struct %s_operation\n{\n",name);
	len += snprintf(row + len, size - len,"    int32_t (*init)(struct %s*);\n",name);
	len += snprintf(row + len, size - len,"    int32_t (*release)(struct %s*);\n",name);
	len += snprintf(row + len, size - len,"    int32_t (*start)(struct %s*);\n",name);
	len += snprintf(row + len, size - len,"    int32_t (*stop)(struct %s*);\n",name);
	len += snprintf(row + len, size - len,"    int32_t (*get_frame)(struct %s*, struct list_head* queue, struct %s_frame** pframe);\n",name,name);
	len += snprintf(row + len, size - len,"    int32_t (*put_frame)(struct %s*, struct list_head* queue, struct %s_frame* pframe);\n",name,name);
	len += snprintf(row + len, size - len,"    int32_t (*register_notify)(struct %s*, int32_t, %s_event_notify notify, void*);\n",name,name);
	len += snprintf(row + len, size - len,"    int32_t (*unregister_notify)(struct %s*, int32_t, void*);\n",name);
	len += snprintf(row + len, size - len,"    int32_t (*trigger_notify)(struct %s*, int32_t, void*);\n",name);
	len += snprintf(row + len, size - len,"};\n\n");
	fwrite(row, len, 1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"struct %s\n{\n",name);
	len += snprintf(row + len, size - len,"    wait_t wait;\n");
	len += snprintf(row + len, size - len,"    lock_t lock;\n");
	len += snprintf(row + len, size - len,"    lock_t notify_lock;\n\n");
	len += snprintf(row + len, size - len,"    struct list_head free_queue;\n");
	len += snprintf(row + len, size - len,"    struct list_head used_queue;\n");
	len += snprintf(row + len, size - len,"    struct %s_frame cache_frames[%s_CACHE_COUNT];\n\n", name, uname);
	len += snprintf(row + len, size - len,"    struct %s_operation* op;\n",name);
	len += snprintf(row + len, size - len,"    struct %s_event_action *paction[%s_EVENT_MAX];\n",name,uname);
	len += snprintf(row + len, size - len,"};\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"int32_t create_init_%s(struct %s** p%s);\n",name,name,name);
	len += snprintf(row + len, size - len,"void release_destroy_%s(struct %s* p%s);\n",name,name,name);
	len += snprintf(row + len, size - len,"\n#endif\n");
	fwrite(row,strlen(row),1,fp);

	fclose(fp);
	return 0;
}

int generate_c(char* name)
{
	int len = 0;
	int size = MAX_ROW_LENGTH;
	char filename[MAX_FILE_NAME];
	char row[MAX_ROW_LENGTH];
	char uname[MAX_FILE_NAME];
	FILE* fp;
	sprintf(filename,"%s/%s.c",GENERATE_PATH,name);
	if(!access(filename,R_OK)){
		printf("%s have existed, will be replaced\n",filename);
		remove(filename);
	}
	fp = fopen(filename,"w+");
	if(!fp){
		printf("open c file error\n");
		return -EFAULT;
	}
	strupr(uname,name);
	
	len = 0;
	len += snprintf(row + len, size - len,"#include <stdlib.h>\n");
	len += snprintf(row + len, size - len,"#include <string.h>\n");
	len += snprintf(row + len, size - len,"#include <errno.h>\n");
	len += snprintf(row + len, size - len,"#include \"log.h\"\n");
	len += snprintf(row + len, size - len,"#include \"%s.h\"\n\n",name);
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"static int32_t %s_init(struct %s* p%s)\n",name,name,name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    int i;\n");
	len += snprintf(row + len, size - len,"    lock_init(&(p%s->lock));\n",name);
	len += snprintf(row + len, size - len,"    lock_init(&(p%s->notify_lock));\n",name);
	len += snprintf(row + len, size - len,"    wait_init(&(p%s->wait));\n",name);
	len += snprintf(row + len, size - len,"    INIT_LIST_HEAD(&(p%s->free_queue));\n",name);
	len += snprintf(row + len, size - len,"    INIT_LIST_HEAD(&(p%s->used_queue));\n",name);
	len += snprintf(row + len, size - len,"    for(i = 0; i < %s_CACHE_COUNT;i ++){\n", uname);
	len += snprintf(row + len, size - len,"	       p%s->op->put_frame(p%s, &p%s->free_queue, &p%s->cache_frames[i]);\n", name, name, name, name);
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	fwrite(row,len,1,fp);

	len = 0;
	len += snprintf(row + len, size - len,"static int32_t %s_release(struct %s* p%s)\n",name,name,name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    lock_destroy((&p%s->notify_lock));\n",name);
	len += snprintf(row + len, size - len,"    lock_destroy((&p%s->lock));\n",name);
	len += snprintf(row + len, size - len,"    wait_destroy((&p%s->wait));\n",name);
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"static int32_t %s_start(struct %s* p%s)\n",name,name,name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"static int32_t %s_stop(struct %s* p%s)\n",name,name,name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	fwrite(row,len,1,fp);

	len = 0;
	len += snprintf(row + len, size - len,"static int32_t %s_get_frame(struct %s* p%s, struct list_head* queue, struct %s_frame** pframe)\n",name,name,name,name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    *pframe = NULL;\n");
	len += snprintf(row + len, size - len,"    lock((&p%s->lock));\n",name);
	len += snprintf(row + len, size - len,"    if(!list_empty(queue)){\n");
	len += snprintf(row + len, size - len,"        *pframe = list_first_entry(queue, struct %s_frame, head);\n",name);
	len += snprintf(row + len, size - len,"        list_del(&(*pframe)->head);\n");
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    unlock((&p%s->lock));\n",name);
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"static int32_t %s_put_frame(struct %s* p%s, struct list_head* queue, struct %s_frame* pframe)\n",name,name,name,name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    lock((&p%s->lock));\n",name);
	len += snprintf(row + len, size - len,"    list_add_tail(&pframe->head, queue);\n");
	len += snprintf(row + len, size - len,"    unlock((&p%s->lock));\n",name);
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"static int32_t %s_register_notify(struct %s* p%s, int32_t event, %s_event_notify notify, void* object)\n",name,name,name,name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    struct %s_event_action* paction;\n",name);
	len += snprintf(row + len, size - len,"    if(!notify || (event <= %s_EVENT_NONE) || (event >= %s_EVENT_MAX)){\n",uname,uname);
	len += snprintf(row + len, size - len,"        return -EINVAL;\n");
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    paction = (struct %s_event_action*)malloc(sizeof(struct %s_event_action));\n",name,name);
	len += snprintf(row + len, size - len,"    if(!paction){\n");
	len += snprintf(row + len, size - len,"        DBG(DBG_ERR,\"malloc error\\n\");\n");
	len += snprintf(row + len, size - len,"        return -ENOMEM;\n");
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    paction->notify = notify;\n");
	len += snprintf(row + len, size - len,"    paction->object = object;\n");
	len += snprintf(row + len, size - len,"    lock(&(p%s->notify_lock));\n",name);
	len += snprintf(row + len, size - len,"    paction->next = p%s->paction[event];\n",name);
	len += snprintf(row + len, size - len,"    p%s->paction[event] = paction;\n",name);
	len += snprintf(row + len, size - len,"    unlock(&(p%s->notify_lock));\n",name);
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"static int32_t %s_unregister_notify(struct %s* p%s, int32_t event, void* object)\n",name,name,name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    struct %s_event_action *paction,* ptmp;\n",name);
	len += snprintf(row + len, size - len,"    if((event <= %s_EVENT_NONE) || (event >= %s_EVENT_MAX)){\n",uname,uname);
	len += snprintf(row + len, size - len,"        return -EINVAL;\n");
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    lock(&(p%s->notify_lock));\n",name);
	len += snprintf(row + len, size - len,"    paction = p%s->paction[event];\n",name);
	len += snprintf(row + len, size - len,"    if(paction){\n");
	len += snprintf(row + len, size - len,"        if(paction->object == object){\n");
	len += snprintf(row + len, size - len,"            p%s->paction[event] = paction->next;\n",name);
	len += snprintf(row + len, size - len,"            free(paction);\n");
	len += snprintf(row + len, size - len,"        }else{\n");
	len += snprintf(row + len, size - len,"            while(paction->next){\n");
	len += snprintf(row + len, size - len,"                if(paction->next->object == object){\n");
	len += snprintf(row + len, size - len,"                    ptmp = paction->next;\n");
	len += snprintf(row + len, size - len,"                    paction->next = ptmp->next;\n");
	len += snprintf(row + len, size - len,"                    free(ptmp);\n");
	len += snprintf(row + len, size - len,"                    break;\n");
	len += snprintf(row + len, size - len,"                }\n");
	len += snprintf(row + len, size - len,"                paction = paction->next;\n");
	len += snprintf(row + len, size - len,"            }\n");
	len += snprintf(row + len, size - len,"        }\n");
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    unlock(&(p%s->notify_lock));\n",name);
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"static int32_t %s_trigger_notify(struct %s* p%s, int32_t event, void* context)\n",name,name,name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    struct %s_event_action* paction;\n",name);
	len += snprintf(row + len, size - len,"    if((event <= %s_EVENT_NONE) || (event >= %s_EVENT_MAX)){\n",uname,uname);
	len += snprintf(row + len, size - len,"        return -EINVAL;\n");
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    lock(&(p%s->notify_lock));\n",name);
	len += snprintf(row + len, size - len,"    paction = p%s->paction[event];\n",name);
	len += snprintf(row + len, size - len,"    while(paction){\n");
	len += snprintf(row + len, size - len,"        paction->notify(p%s, event, paction->object, context);\n",name);
	len += snprintf(row + len, size - len,"        paction = paction->next;\n");
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    unlock(&(p%s->notify_lock));\n",name);
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"static struct %s_operation %s_op =\n{\n",name,name);
	len += snprintf(row + len, size - len,"    .init = %s_init,\n",name);
	len += snprintf(row + len, size - len,"    .release = %s_release,\n",name);
	len += snprintf(row + len, size - len,"    .start = %s_start,\n",name);
	len += snprintf(row + len, size - len,"    .stop = %s_stop,\n",name);
	len += snprintf(row + len, size - len,"    .get_frame = %s_get_frame,\n",name);
	len += snprintf(row + len, size - len,"    .put_frame = %s_put_frame,\n",name);
	len += snprintf(row + len, size - len,"    .register_notify = %s_register_notify,\n",name);
	len += snprintf(row + len, size - len,"    .unregister_notify = %s_unregister_notify,\n",name);
	len += snprintf(row + len, size - len,"    .trigger_notify = %s_trigger_notify,\n",name);
	len += snprintf(row + len, size - len,"};\n\n");
	fwrite(row,len,1,fp);
	
	len = 0;
	len += snprintf(row + len, size - len,"int32_t create_init_%s(struct %s** p%s)\n",name,name,name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    int32_t ret;\n");
	len += snprintf(row + len, size - len,"    struct %s* ptmp;\n",name);
	len += snprintf(row + len, size - len,"    (*p%s) = (struct %s*)malloc(sizeof(struct %s));\n",name,name,name);
	len += snprintf(row + len, size - len,"    if(!(*p%s)){\n",name);
	len += snprintf(row + len, size - len,"        DBG(DBG_ERR,\"malloc error\\n\");\n");
	len += snprintf(row + len, size - len,"        return -ENOMEM;\n");
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    ptmp = *p%s;\n",name);
	len += snprintf(row + len, size - len,"    memset(ptmp,0,sizeof(struct %s));\n",name);
	len += snprintf(row + len, size - len,"    ptmp->op = &%s_op;\n",name);
	len += snprintf(row + len, size - len,"    ret = ptmp->op->init(ptmp);\n");
	len += snprintf(row + len, size - len,"    if(ret < 0){\n");
	len += snprintf(row + len, size - len,"        DBG(DBG_ERR,\"init error\\n\");\n");
	len += snprintf(row + len, size - len,"        release_destroy_%s(ptmp);\n",name);
	len += snprintf(row + len, size - len,"        return ret;\n");
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	fwrite(row,len,1,fp);

	len = 0;
	len += snprintf(row + len, size - len,"void release_destroy_%s(struct %s* p%s)\n",name,name,name);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    if(p%s){\n",name);
	len += snprintf(row + len, size - len,"        p%s->op->release(p%s);\n",name,name);
	len += snprintf(row + len, size - len,"        free(p%s);\n",name);
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"}\n\n");
	fwrite(row,len,1,fp);

	fclose(fp);
	return 0;
}

void generate_cd(char* parent, char* child)
{
	int len;
	int size = MAX_ROW_LENGTH;
	char row[MAX_ROW_LENGTH];
	
	len = 0;
	len += snprintf(row + len, size - len,"    int32_t (*create_%s)(struct %s*);\n",child,parent);
	len += snprintf(row + len, size - len,"    int32_t (*destroy_%s)(struct %s*);\n",child,parent);
	printf("\n\n\n%s\n", row);

	len = 0;
	len += snprintf(row + len, size - len,"    .create_%s = %s_create_%s,\n",child,parent,child);
	len += snprintf(row + len, size - len,"    .destroy_%s = %s_destroy_%s,\n",child,parent,child);
	printf("%s\n", row);

	len = 0;
	len += snprintf(row + len, size - len,"static int32_t %s_create_%s(struct %s* p%s)\n",parent,child,parent,parent);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    int32_t ret;\n");
	len += snprintf(row + len, size - len,"    struct %s* p%s;\n", child, child);
	len += snprintf(row + len, size - len,"    ret = create_init_%s(&p%s->p%s);\n",child,parent,child);
	len += snprintf(row + len, size - len,"    if(ret < 0){\n");
	len += snprintf(row + len, size - len,"        DBG(DBG_ERR,\"create %s error\\n\");\n", child);
	len += snprintf(row + len, size - len,"        return ret;\n");
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    p%s = p%s->p%s;\n", child, parent, child);
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	printf("%s", row);

	len = 0;
	len += snprintf(row + len, size - len,"static int32_t %s_destroy_%s(struct %s* p%s)\n",parent,child,parent,parent);
	len += snprintf(row + len, size - len,"{\n");
	len += snprintf(row + len, size - len,"    struct %s* p%s;\n", child, child);
	len += snprintf(row + len, size - len,"    if(p%s->p%s){\n",parent, child);
	len += snprintf(row + len, size - len,"        p%s = p%s->p%s;\n", child, parent, child);
	len += snprintf(row + len, size - len,"        release_destroy_%s(p%s);\n",child,child);
	len += snprintf(row + len, size - len,"        p%s->p%s = NULL;\n",parent,child);
	len += snprintf(row + len, size - len,"    }\n");
	len += snprintf(row + len, size - len,"    return 0;\n");
	len += snprintf(row + len, size - len,"}\n\n");
	printf("%s", row);

	len = 0;
	len += snprintf(row + len, size - len,"    ret = p%s->op->create_%s(p%s);\n", parent, child, parent);
	len += snprintf(row + len, size - len,"    if(ret < 0){\n");
	len += snprintf(row + len, size - len,"        DBG(DBG_ERR, \"%s create %s error\\n\");\n",parent, child);
	len += snprintf(row + len, size - len,"    }\n");
	printf("%s\n", row);

	len = 0;
	len += snprintf(row + len, size - len,"    p%s->op->destroy_%s(p%s);\n", parent, child, parent);
	printf("%s\n", row);

	len = 0;
	len += snprintf(row + len, size - len,"    struct %s* p%s;\n", child, child);
	len += snprintf(row + len, size - len,"    p%s = p%s->p%s;\n", child, parent, child);
	len += snprintf(row + len, size - len,"    ret = p%s->op->start(p%s);\n", child, child);
	len += snprintf(row + len, size - len,"    if(ret < 0){\n");
	len += snprintf(row + len, size - len,"        DBG(DBG_ERR, \"start %s error\\n\");\n", child);
	len += snprintf(row + len, size - len,"    }\n\n");
	printf("%s\n", row);

	len = 0;
	len += snprintf(row + len, size - len,"    struct %s* p%s;\n", child, child);
	len += snprintf(row + len, size - len,"    p%s = p%s->p%s;\n", child, parent, child);
	len += snprintf(row + len, size - len,"    ret = p%s->op->stop(p%s);\n", child, child);
	len += snprintf(row + len, size - len,"    if(ret < 0){\n");
	len += snprintf(row + len, size - len,"        DBG(DBG_ERR, \"stop %s error\\n\");\n", child);
	len += snprintf(row + len, size - len,"    }\n\n");
	printf("%s\n", row);

}

int main(int argc,char* argv[])
{
	int ret;
	if(argc < 2){
		printf("Please input generate class name !\n");
		printf("Please input generate parent class name and chlid class name !\n");
		return -EINVAL;
	}
	if(argc == 2){
		ret = access(GENERATE_PATH,R_OK);
		if(ret != 0){
			ret = mkdir(GENERATE_PATH,0777);
			if(ret != 0){
				printf("create %s path error, ret = %d\n",GENERATE_PATH,ret);
				perror("error:\n");
				return ret;
			}
		}
		if(generate_h(argv[1]) < 0){
			printf("generate h file error\n");
		}
		if(generate_c(argv[1]) < 0){
			printf("generate c file error\n");
		}
	}
	if(argc == 3){
		generate_cd(argv[1], argv[2]);
	}
	return 0;
}
